﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BeatEmUp.Characters;
using BeatEmUp.World;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace BeatEmUp.Characters
{
    public static class CollisionManager
    {
        public static List<Rectangle> blockedPlaces;

        public static bool IsPositionValid(Rectangle playerPosition)
        {
            Rectangle position = new Rectangle(playerPosition.X,
                playerPosition.Y + playerPosition.Height - 10,
                playerPosition.Width,
                10);

            position.Height = 10;

            foreach (Rectangle blockedPlace in blockedPlaces)
            {
                if (blockedPlace.Intersects(position))
                    return false;
            }

            return true;
        }

        public static void CreateListFromConfig(Config<StaticElement> config, Viewport viewport)
        {
            blockedPlaces = new List<Rectangle>(config.CurrentElements.Count);

            foreach (StaticElement element in config.CurrentElements)
            {
                blockedPlaces.Add(element.GetCollisionRect(viewport));
            }
        }

    }
}
